package org.yzhzc.system.controller.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yzhzc.common.core.controller.BaseController;
import org.yzhzc.common.core.domain.R;
import org.yzhzc.common.core.domain.TableDataInfo;
import org.yzhzc.common.core.enums.ResultCode;
import org.yzhzc.system.domain.user.dto.UserDTO;
import org.yzhzc.system.domain.user.dto.UserQueryDTO;
import org.yzhzc.system.service.user.IUserService;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Autowired
    private IUserService userService;


    @GetMapping("/list")
    public TableDataInfo list(UserQueryDTO userQueryDTO) {
        TableDataInfo rspData = new TableDataInfo();
        try{
            rspData = getTableDataInfo(userService.list(userQueryDTO));
        }catch (Exception e){
            rspData.setCode(ResultCode.FAILED.getCode());
            rspData.setMsg(e.getMessage());
        }
        return rspData;
    }


    //todo 拉黑：限制用户操作   解禁：放开对于用户限制
    //更新数据库中用户的状态信息。
    @PutMapping("/updateStatus")
    public R<Void> updateStatus(@RequestBody UserDTO userDTO) {
        return toR(userService.updateStatus(userDTO));
    }
}